#ifndef CPP_FONT_H
#define CPP_FONT_H

#include <sstream>
#include <string>
#include <Global.h>
#include <MiniGui.h>

#define DEFAULT_FONT_NAME "sanshans"

//@brief font
//@author cvte
class Font {
   public:
    class Builder {
       public:
        Builder() {
            cvte_log_info("Font Builder build");
            mType = "ttf";
            mFamily = DEFAULT_FONT_NAME;
            mCharset = "UTF-8";
            mWeight = FONT_WEIGHT_BOOK;
            mSlant = FONT_SLANT_ROMAN;
            mFlip = FONT_FLIP_NIL;
            mOther = FONT_OTHER_AUTOSCALE;
            mUnderline = FONT_UNDERLINE_NONE;
            mStruckout = FONT_STRUCKOUT_NONE;
            mSize = 20;
            mRotation = 0;
        }

        Builder(const char* fontName, int size, bool isBold) : mFamily(fontName), mSize(size) {
            cvte_log_info("Font Builder 3 params build");
            mType = "ttf";
            mCharset = "UTF-8";
            mWeight = isBold ? FONT_WEIGHT_BOLD : FONT_WEIGHT_BOOK;
            mSlant = FONT_SLANT_ROMAN;
            mFlip = FONT_FLIP_NIL;
            mOther = FONT_OTHER_AUTOSCALE;
            mUnderline = FONT_UNDERLINE_NONE;
            mStruckout = FONT_STRUCKOUT_NONE;
            mRotation = 0;
        }

        ~Builder() {

        }

        void setType(const char* type) { mType = type; };
        const char* getType() { return mType; };
        void setFamily(const char* family) { mFamily = family; };
        const char* getFamily() { return mFamily; };
        void setCharset(const char* charset) { mCharset = charset; };
        const char* getCharset() { return mCharset; };
        void setWeight(char weight) { mWeight = weight; };
        char getWeight() { return mWeight; };
        void setSlant(char slant) { mSlant = slant; };
        char getSlant() { return mSlant; };
        void setFlip(char flip) { mFlip = flip; };
        char getFlip() { return mFlip; };
        void setOther(char other) { mOther = other; };
        char getOther() { return mOther; };
        void setUnderline(char underline) { mUnderline = underline; };
        char getUnderline() { return mUnderline; }
        void setStruckout(char struckout) { mStruckout = struckout; };
        char getStruckout() { return mStruckout; };
        void setSize(int size) { mSize = size; };
        int getSize() { return mSize; }
        void setRotation(int rotation) { mRotation = rotation; };
        int getRotation() { return mRotation; };

        const std::string createFontCacheKey() {
            std::ostringstream ostr1;
            ostr1 << mType << '_' << mFamily << '_' << mCharset << '_' << mWeight << '_' << mSlant << '_';
            char flip = (mFlip == FONT_FLIP_NIL) ? '0' : mFlip;
            char other = (mOther == FONT_OTHER_NIL) ? '0' : mOther;
            char underline = (mUnderline == FONT_UNDERLINE_NIL) ? '0' : mUnderline;
            char struckout = (mStruckout == FONT_STRUCKOUT_NIL) ? '0' : mStruckout;
            ostr1 << flip << '_' << other << '_' << underline << '_' << struckout << '_' << mSize << '_' << mRotation;
            const std::string fontCacheKey = ostr1.str();
            cvte_log_info("font cache key:%s", fontCacheKey.c_str());
            return fontCacheKey;
        };

       protected:
        const char* mType;
        const char* mFamily;
        const char* mCharset;
        char mWeight;
        char mSlant;
        char mFlip;
        char mOther;
        char mUnderline;
        char mStruckout;
        int mSize;
        int mRotation;
    };
    Font(const char* fontName, int fontSize);
    Font(Builder& builder);
    ~Font();

    PLOGFONT getLogFontPointer(void);

   private:
    PLOGFONT mPLogFont;
};

#endif /* CPP_FONT_H */